#!/bin/bash
###SHELLPACK preamble wis-install 0
GIT_LOCATION=https://github.com/antonblanchard/will-it-scale.git
MIRROR_LOCATION="$WEBROOT/wis/"

###SHELLPACK parseargBegin
###SHELLPACK parseargEnd

install-depends hwloc-devel

###SHELLPACK self_extract align-alloc.patch

###SHELLPACK git_fetch wis-${VERSION}.tar.gz wis-${VERSION}-installed

###SHELLPACK build_start wis-${VERSION}-installed
cat $SHELLPACK_TEMP/align-alloc.patch | patch -p1
sed -i -e 's/tmpfs/tmp/' tests/fallocate1.c
sed -i -e 's/\/tmp\/willitscale/willitscale/' tests/*.c
sed -i -e 's/\/tmp\/shared_area/shared_area/' main.c
###SHELLPACK make

echo will-it-scale installed successfully
exit $SHELLPACK_SUCCESS

==== BEGIN align-alloc.patch ====
diff --git a/tests/read3.c b/tests/read3.c
index fdbd33086caf..0faf23ba9195 100644
--- a/tests/read3.c
+++ b/tests/read3.c
@@ -17,7 +17,11 @@ void testcase(unsigned long long *iterations, unsigned long nr)
 	int fd = mkostemp(tmpfile, O_DIRECT);
 	char *p;
 
+#ifdef _ISOC11_SOURCE
 	buf = aligned_alloc(getpagesize(), FILESIZE);
+#else
+	posix_memalign(&buf, getpagesize(), FILESIZE);
+#endif
 	memset(buf, 0, FILESIZE);
 	assert(fd >= 0);
 	assert(write(fd, buf, FILESIZE) == FILESIZE);
diff --git a/tests/read4.c b/tests/read4.c
index cb097e753800..3f6e437e0bd4 100644
--- a/tests/read4.c
+++ b/tests/read4.c
@@ -28,7 +28,11 @@ void testcase(unsigned long long *iterations, unsigned long nr)
 	int fd = open(tmpfile, O_DIRECT|O_RDONLY);
 	char *p;
 
-	p = aligned_alloc(getpagesize(), BUFLEN);
+#ifdef _ISOC11_SOURCE
+        p = aligned_alloc(getpagesize(), FILESIZE);
+#else
+        posix_memalign(&p, getpagesize(), FILESIZE);
+#endif
 
 	while (1) {
 		int ret = read(fd, p, BUFLEN);
==== END align-alloc.patch ====
